package PlaneGame.CODE;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

public class EnemyB extends Enemy{
    int shotRate =50,shotR=0;//速率越小越快

    public EnemyB() {
        super();
        this.speed=2;
        this.width=40;
        this.height=40;
        this.imageNumber=2;
        this.explodeImageNumber=4;
        this.paths= new String[]{"src/PlaneGame/IMAGE/enemy2.png",
                "src/PlaneGame/IMAGE/enemy2_hit.png",
                "src/PlaneGame/IMAGE/enemy2_down1.png",
                "src/PlaneGame/IMAGE/enemy2_down2.png",
                "src/PlaneGame/IMAGE/enemy2_down3.png",
                "src/PlaneGame/IMAGE/enemy2_down4.png"};
        images=new BufferedImage[imageNumber+explodeImageNumber];
        for (int i = 0; i < images.length; i++) {
            try {
                images[i] = ImageIO.read(new File(paths[i]));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
    }
    @Override
    void init() {
        super.init();
        blood=3;
    }
    @Override
    void change() {
        super.change();
        shot();
    }
    void shot(){
        delete();
        shotR++;
        if(shotR>shotRate){
            create();
            shotR=0;
        }
    }
    void create(){
        tVector.add(new EnemyBullet((this.x+this.width/2),(this.y+this.height)));
        tVector.lastElement().shift();
        new Thread(tVector.lastElement()).start();
    }
    void delete(){
        for (int i = 0; i < tVector.size(); i++) {
            if(!tVector.elementAt(i).on_off){
                tVector.removeElementAt(i);
            }
        }
    }
    @Override
    void draw(Graphics g) {
        super.draw(g);
        drawVector(g);
    }
    void drawVector(Graphics g){
        for (int i = 0; i < tVector.size(); i++) {
            tVector.elementAt(i).drawMyself(g);
        }
    }

}
